/*
 * @Author: ChunLai
 * @Date: 2022-09-27 14:23:37
 * @LastEditTime: 2025-07-30 15:02:00
 * @Description: 保单信息填入
 * @FilePath: \02.bldinsure\src\mixins\info_bill.js
 */
import { mapGetters } from "vuex";
import { tellPhoneFormat } from "@/methods/format.js";

export const inputInfoForBillMixin = {
  computed: {
    ...mapGetters({
      bankR: "dictionary/bankR",
      bank7: "dictionary/bank7",
      terminalMsg: "insert/terminalMsg", // 设备信息
      payModeList: "dictionary/payModeList",
      autoPayList: "dictionary/autoPayList",
      exModeList: "dictionary/exModeList",
      aliveModeList: "dictionary/aliveModeList",
      contractTypeList: "dictionary/contractTypeList",
      yesNoCheckList: "dictionary/yesNoCheckList",
      inputReg: "infoReg/inputReg",
      selfFieldDesc: "dictionary/selfFieldDesc",
      totalPrem: "insert/totalPrem",
    }),
    infoReg() {
      return JSON.parse(JSON.stringify(this.inputReg.payInfo));
    },
    viewOptions() {
      return this.popConfig.list.filter(
        (item) => item.text && item.text.indexOf(this.keyWord) !== -1
      );
    },
    cpPhoneNum: {
      get: function () {
        if (this.foI4) {
          return this.orderInfo.firBankMobile;
        }
        return tellPhoneFormat(this.orderInfo.firBankMobile);
      },
      set: function (val) {
        this.changeData({
          firBankMobile: val.replace(/\s*/g, ""),
        });
      },
    },
  },
  watch: {
    bankCodeName(val) {
      for (const key in this.bankLimit) {
        this.bankLimit[key] = "";
      }
      const len = this.bankList.length;
      for (let i = 0; i < len; i++) {
        const item = this.bankList[i];
        if (item.text === val) {
          this.bankLimit.text = item.text;
          this.bankLimit.oneLimit = item.small || "";
          this.bankLimit.dayLimit = item.big || "";
          if (item.batch) {
            this.bankLimit.batch = item.batch || "";
          }
          let lfee = item.limitR;
          if (this.orderInfo.payMode == "7") {
            lfee = item.limitB || "无限额";
          }
          if (lfee && lfee != "无限额") {
            this.bankLimit.fee = lfee;
          }
          this.$store.commit("page/SET_PAGE_CONFIG", {
            limitFeeObj: this.bankLimit,
          });
          break;
        }
      }
    },
  },
  methods: {
    changeData(data) {
      Object.assign(this.orderInfo, data);
      this.$forceUpdate();
    },
    showPopAction(type, key, list, curVal) {
      this.defaultIndex = 0;
      if (list.length == 1) {
        return;
      }
      this.popConfig = {
        type,
        key,
        list,
      };
      if (list.length > 0) {
        let defaultIndex = list.findIndex(
          (item) => curVal == item.keyId || item.default
        );
        if (defaultIndex > 0) {
          this.defaultIndex = defaultIndex;
        }
      }
      // console.log(this.popConfig);
      this.showPop = true;
    },
    initTipField(fname) {
      if (!this.tipsInfo[`${fname}`]) return;
      let obj = {};
      obj[`${fname}`] = "";
      Object.assign(this.tipsInfo, obj);
      this.$forceUpdate();
    },
  },
};

export const InsureBtnHandleMixin = {
  computed: {
    ...mapGetters({
      omnipotentNaire: "page/omnipotentNaire",
      omnipApiNaire: "page/omnipApiNaire",
      omnipApiNaireEx: "page/omnipApiNaireEx",
      presureCfg: "page/presureCfg",
      preNotice: "page/preNotice",
      noticeConfigType: "page/noticeConfigType",
    }),
    isOmnipotent() {
      let res = false;
      if (
        this.omnipotentNaire.length > 0 &&
        this.omnipotentNaire.includes(this.mainRiskCode)
      ) {
        res = true;
      }
      return res;
    },
    isApiOmnipotent() {
      let res = false;
      if (this.omnipApiNaire == "1") {
        res = true;
        if (
          this.omnipApiNaireEx.length > 0 &&
          this.omnipApiNaireEx.includes(this.mainRiskCode)
        ) {
          res = false;
        }
      }

      return res;
    },
    isPreSurePage() {
      let res = false;
      if (this.presureCfg && this.presureCfg.length > 0) {
        res = true;
      }
      return res;
    },
  },
  methods: {
    nextRouterMixin() {
      // 互联网简易告知(取消)
      if (this.noticeConfigType === "1") {
        return this.$router.push("/nethealthy");
      }
      if (this.preNotice) {
        this.$router.push("/prenotice"); // 前置告知
        return;
      }
      if (this.isOmnipotent) {
        this.$router.push("/qnaire"); // 万能问卷
        return;
      }
      if (this.isApiOmnipotent) {
        this.$router.push("/risknair"); // 接口万能问卷
        return;
      }
      if (this.isPreSurePage) {
        this.$router.push("/presure");
        return;
      }
      this.$router.push("/form");
    },
  },
};
